<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, ValidatesRequests;

    function message($view, $info, $data = []) {
        $layerMsg = [
            'result' => "layer.msg('" . $info  . "', {icon: 0}, function(){
        // layer.msg('提示框关闭后的回调');
      });"
        ];
        return view($view, array_merge($layerMsg, $data));
    }



    function jsonMessage($code = 0, $info = '', $data = [])
    {
        return response()->json([
            'code' => $code,
            'info' => $info,
            'data' => $data
        ]);
    }

    function ok($info = '', $data = [])
    {
        return $this->jsonMessage(0, $info, $data);
    }

    function error($info = '', $data = [])
    {
        return $this->jsonMessage(1, $info, $data);
    }

    function paginate($info = '', $data)
    {
        return response()->json([
            'code' => 0,
            'info' => $info,
            'count' => $data->total(),
            'data' => $data->items(),
        ]);
    }
}
